/*
 * Copyright 2002-2007 the original author or authors.
 *
 * Licensed under the Apache license, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.internna.iwebjtracker.project.model;

import java.util.Collection;
import java.util.Date;
import org.internna.iwebjtracker.project.validation.Errors;

/**
 * A release/distribution of a projext.
 *
 * @author Jose Noheda
 * @since 1.0
 */
public interface Version<U extends IWebJTrackerUser, P extends Project<?, ?, V, U, P>, V extends Version<U, P, V>> {

    /**
     * The identifier of this version. Usually in the form of major.minor.relase and optionally a suffix, ie 2.0.4-SNAPSHOT
     *
     * @return a not empty string
     */
    String getLabel();

    /**
     * Establish a new version label (must not be null or empty)
     *
     * @param newLabel any (null or empty labels are bypassed)
     */
    void setLabel(String newLabel);

    /**
     * Date by which this version should be finished.
     *
     * @return any date
     */
    Date getDueDate();

    /**
     * Establish a new version end date.
     *
     * @param due any
     */
    void setDueDate(Date due);

    /**
     * Determines if this version is the one under heavy work right now.
     *
     * @return a boolean
     */
    boolean isCurrentVersion();

    /**
     * Retrieve all versions that have this version as parent.
     */
    Collection<V> getMilestones();

    /**
     * Returns the project this version belongs to.
     */
    P getParentProject();

    /**
     * Establish the parent project.
     */
    void setParentProject(P project);

    /**
     * Adds a new version previously created.
     *
     * @param version any
     * @return any
     */
    V addMilestone(V version);

    /**
     * Creates a new version from the provided data.
     *
     * @param name any (if empty no version is created)
     * @param dueDate any
     * @return any
     */
    V createMilestone(String name, Date dueDate);

    /**
      * Checks if this version is closed (no new issues or activity in it)
      *
      * @return false unless the version has been closed
      */
     boolean isClosed();

     /**
      * Closes the project disallowing activity from now on.
      *
      * @param user any
      * @return null if the version was closed successfully, otherwise the problem
      */
     Errors close(U user);

}
